<?php

$disallow = array(
'./cache', './files_check.php'
);

$extensions = array( 'php', 'html', 'xml', 'css', 'js');

$lines_number = 0;

$files_number = 0;

$files_list = array();

$types_list = array();

checkDir( './');

//echo result
echo 'Project contains '.$lines_number.' lines of code in '.$files_number.' files';
echo '<br /><br />';
echo '==============================================================================================';
echo '<br />TYPES LISTING<br />';
echo '==============================================================================================';
echo '<br />';
foreach ( $types_list as $type_id => $lines){
	echo '<br />'.$type_id.' ['.$lines.']';
}
echo '<br /><br />';
echo '==============================================================================================';
echo '<br />FILES LISTING<br />';
echo '==============================================================================================';
echo '<br /><br />';
echo join( "<br />", $files_list);

//function
function checkDir( $dir){
	
	//globals
	global $disallow;
	global $lines_number;
	global $files_number;
	global $types_list;
	global $files_list;
	global $extensions;
	
	//get all
	$dir_content = glob( $dir.'*');
	
	//iterate
	foreach ( $dir_content as $item){
		
		//not in list
		if ( !in_array( $item, $disallow)){

			//dir?
			if ( is_dir( $item)){
				
				//run iteration again
				checkDir( $item.'/');
					
			}else{
				
				//get file extension
				$file_extension = substr( $item, strrpos( $item, '.') + 1);
				
				//is this what we like?
				if ( in_array( $file_extension, $extensions)){
					
					//key exists?
					if ( !key_exists( $file_extension, $types_list))
						$types_list[$file_extension] = 0;
					
					//increase files number
					$files_number ++;
					
					//open file
					$file_cotent = file_get_contents( $item);
					
					//get lines number
					$lines_number += substr_count( $file_cotent, "\n");
					
					//get lines number
					$types_list[$file_extension] += substr_count( $file_cotent, "\n");
					
					//add to list
					$files_list[] = $item.' ['.substr_count( $file_cotent, "\n").']';
					
				}
				
			}
			
		}
		
	}
	
}

?>